import java.util.Scanner;

//进制转换
public class HJ5 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String str = sc.nextLine();
            str = str.substring(2);
            int sum = 0;
            for (int i = 0; i < str.length(); i++) {
                Integer anInt = getInt(str.charAt(i));
                sum += (int) (anInt * Math.pow(16, str.length() - 1 - i));
            }
            System.out.println(sum);
        }
    }
    
    public static Integer getInt (char numStr) {
        switch (numStr) {
            case 'A':
                return 10;
            case 'B':
                return 11;
            case 'C':
                return 12;
            case 'D':
                return 13;
            case 'E':
                return 14;
            case 'F':
                return 15;
            default:
                return Integer.parseInt(String.valueOf(numStr));
        }
    }
}
